#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDebug"
#include "QString"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //初始化
    setFixedSize(this->width(), this->height());
    this->setWindowTitle("邹老板专用");
    this->setStyleSheet("background-color:pink;");

    ui->spinBox_h1->setMaximum(12);
    ui->spinBox_h1->setMinimum(0);
    ui->spinBox_h2->setMaximum(12);
    ui->spinBox_h2->setMinimum(0);

    ui->spinBox_m1->setMaximum(60);
    ui->spinBox_m1->setMinimum(0);
    ui->spinBox_m2->setMaximum(60);
    ui->spinBox_m2->setMinimum(0);

    ui->spinBox_s1->setMaximum(60);
    ui->spinBox_s1->setMinimum(0);
    ui->spinBox_s2->setMaximum(60);
    ui->spinBox_s2->setMinimum(0);

    ui->label_end->setText("结果显示");

    //加
    connect ( ui->pushButton_1, &QPushButton::clicked, this,  [=](){
        int hout, mout, sout;
        hout = ui->spinBox_h1->value() + ui->spinBox_h2->value();
        mout = ui->spinBox_m1->value() + ui->spinBox_m2->value();
        sout = ui->spinBox_s1->value() + ui->spinBox_s2->value();
        if(sout >= 60)
        {
            sout -= 60;
            mout += 1;
        }
        if(mout >= 60)
        {
            mout -= 60;
            hout += 1;
        }
        QString ans = QString("%1时%2分%3秒").arg(hout).arg(QString::number(mout)).arg(QString::number(sout));
        ui->label_end->setText(ans);
    }  );

    //减
    connect ( ui->pushButton_2, &QPushButton::clicked, this,  [=](){
        int hout, mout, sout;
        hout =  - ui->spinBox_h1->value() + ui->spinBox_h2->value();
        mout =  - ui->spinBox_m1->value() + ui->spinBox_m2->value();
        sout =  - ui->spinBox_s1->value() + ui->spinBox_s2->value();
        if(sout < 0)
        {
            sout += 60;
            mout -= 1;
        }
        if(mout < 0)
        {
            mout += 60;
            hout -= 1;
        }
        QString ans = QString("%1时%2分%3秒").arg(hout).arg(QString::number(mout)).arg(QString::number(sout));
        ui->label_end->setText(ans);
    }  );



}

MainWindow::~MainWindow()
{
    delete ui;
}
